// POJ 1458
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

const int MAXN = 600;
char a[MAXN];
char b[MAXN];
int la, lb;


int dp[MAXN][MAXN];
int solveA()
{
	// dp[x][y], the first x chars of a, the first y chars of b
	for (int i = 0; i <= la; i++)
		dp[i][0] = 0;
	for (int i = 0; i <= lb; i++)
		dp[0][i] = 0;
	for (int i = 1; i <= la; i++)
		for (int j = 1; j <= lb; j++)
		{
			if (a[i - 1] == b[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
		}
	return dp[la][lb];
}

void printA(int x, int y)
{
	if (x <= 0 || y <= 0)
		return;

	if (a[x - 1] == b[y - 1])
	{
		printA(x - 1, y - 1);
		printf("%c", a[x - 1]);
	}
	else
	{
		if (dp[x][y - 1] >= dp[x - 1][y])
			printA(x, y - 1);
		else
			printA(x - 1, y);
	}
}

int dpb[2][MAXN];
int solveB()
{
	for (int i = 0; i <= lb; i++)
		dpb[1][i] = dpb[0][i] = 0;
	for (int i = 1; i <= la; i++)
		for (int j = 1; j <= lb; j++)
		{
			int m = (i - 1) % 2;
			int n = i % 2;
			if (a[i - 1] == b[j - 1])
				dpb[n][j] = dpb[m][j - 1] + 1;
			else
				dpb[n][j] = max(dpb[n][j - 1], dpb[m][j]);
		}
	return dpb[la % 2][lb];
}

int main()
{
	while (scanf("%s%s", a, b) != EOF)
	{
		la = strlen(a);
		lb = strlen(b);
		printf("%d\n", solveB());
	}
	system("pause");
	return 0;
}